# -*- coding = utf-8 -*-
# @Time    : 2025/3/12 下午2:52
# @Author  : yqk
# @File    : 字符串、列表、元组、字典.py
# @Software: PyCharm

# 1.字符串


word = '字符串'
sentence = '这是一个句子'
paragraph = '''
    这是一个段落
    可以由多行组成
'''

'''
print(word)
print(sentence)
print(paragraph)

'''




# str = "chengdu"
# print(str[0])
# print("你好"+str)
# print("hello\ncu")
# print(r"hello\cu")


# 2.列表
'''

name = ['chengdu','beijing','shanghai']
for item in name:
    print(item)

i = 0
while i < len(name):
    print(name[i])
    i += 1

name.append('chengdu2')
for item in name:
    print(item)


'''



'''

# 增
a = [1, 2]
b = [3, 4]
a.append(b)
print(a)

a.extend(b)
print(a)

a.insert(0, 0)
print(a)

# 删
del a[0]
# a.remove(0)
print(a)
a.remove([3, 4])
print(a)
a.pop()
print(a)

# 改
a[0] = 1
print(a)

# 查【in 、not in】
a = [1, 2, 3, 3]
if 1 in a:
    print("存在")
else:
    print("不存在")
print(a.index(1, 0, 2)) # 返回索引位置，注意：2 是切片的结束位置，不包括 2 本身，即搜索的范围是 [1, 2]）
print(a.count(3))

'''


'''
import random

offices = [[], [], []]

names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']

for name in names:
    a = random.randint(0, 2)
    offices[a].append(name)

j=1
for i in offices:
    print("办公室%d的人数为:%d" %(j,len(i)))
    j+=1
    for item in i:
        print(item,end="\t")
    print()
'''

'''
products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499], ["Coffee", 31], ["Book", 60], ["Nike", 699]]

print("------商品列表------")
i = 0
for product in products:
    name, price = product
    print(i, name, price)
    i += 1

total_price = 0
cart = []
while True:
    user_input = input("请输入商品编号购买，或输入 'q' 退出：")

    if user_input == 'q': 
        break
  
    if user_input.isdigit():
        index = int(user_input)
        if 0 <= index < len(products):
            cart.append(products[index])
            total_price += products[index][1]  
            print(f"已加入购物车：{products[index][0]}")
        else:
            print("无效的商品编号，请重新输入。")
    else:
        print("无效输入，请输入数字编号或 'q' 退出。")

print("\n------购物车------")
if cart:
    for item in cart:
        print(f"{item[0]} {item[1]}")
    print(f"\n总价：{total_price}")
else:
    print("购物车为空。")

'''

# 3.元组

'''

tup = (1, 2, 3)
tup2 = ('a', 'b')
print(tup + tup2)

'''


# 4.字典

'''

info = {'name': 'chengdu','age': 18,'height': 1.88}

print(info['name'])
print(info['age'])
print(info.get('name'))
print(info.get('name222','m'))


'''


'''
# 增

info = {'name': 'chengdu', 'age': 18, 'height': 1.88}
info_id = input("请输入ID:")
info['id'] = info_id
print(info)

# 删 【del，clear】
del info['name']
print(info)

info.clear()
print(info)
# 改

info['name'] = 'chengdu2'
print(info)

# 查

for key, value in info.items():
    print(key, value)

'''


my_list = ['Abc', 'ab', 'ac']
for i, x in enumerate(my_list):
    print(i ,x)



